import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { parts, optionCarType, optionPayStatus } from '../HuoCustmp.model';

@Component({
  selector: 'app-HuoCusPro',
  templateUrl: './HuoCusPro.component.html',
  styleUrls: ['./HuoCusPro.component.scss']
})
export class HuoCusProComponent implements OnInit {
  public deliverTime:string = null;
  public data = [];
  public _total = 0;
  public pageIndex = 1;
  public parts: parts = new parts();
  public optionCarType = optionCarType;
  public optionPayStatus = optionPayStatus;
  
  optionOrderStatus = [
    { value: 1, label: '已发布' },
    { value: 2, label: '已指派' },
    { value: 3, label: '运输中' }, 
    { value: 4, label: '已完成' }, 
    { value: 5, label: '已取消' }, 
    { value: 6, label: '已拒绝' }, 
];

  constructor(
      public apiService: ApiService,
  ) { }

  ngOnInit() {
    this.loadAll();
  }


  loadAll(){
    let url = "findallorder";
    //下面的if语句是因为组件的删除会有一个null值残留，影响get请求。
    if(this.deliverTime){
      this.parts.deliverTime=this.apiService.formatDateTime2(this.deliverTime);
    }else if(!this.deliverTime){
      delete this.parts.deliverTime;
    }
    if(!this.parts.orderStatus){
      delete this.parts.orderStatus;    
    }
    if(!this.parts.carType){
      delete this.parts.carType;    
    }
    if(!this.parts.payStatus){
      delete this.parts.payStatus;
    }
    console.log(this.parts);
    this.apiService.get(url,this.parts)
      .then(res =>{
        console.log(res);
        this._total = res.totalCount;
        this.data = res.result;
      })
  }

    resetIndex(e) {
        this.parts.setPage(e);
        this.loadAll();
  }


}
